/*
 Xern Entity Relocation Network
 Copyright (C) 2010-2011 Ronie Salgado <roniesalg@gmail.com>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
*/

#ifndef XERN_LAMP_HPP
#define XERN_LAMP_HPP

#include <OgreRoot.h>
#include "Xern/ILight.hpp"
#include "Xern/ISerializableResource.hpp"
#include "Xern/Json.hpp"
#include "IOgreObject.hpp"

namespace XernOgre
{
	using namespace Xern;

	class OgreRenderer;
	class Light: public ILight, public ISerializableResource,
		public IOgreObject
	{
	public:
		Light(Ogre::SceneManager *scene, Ogre::Light *light);
		~Light();

		virtual Ogre::MovableObject *GetMovable();
		virtual void DelayAttach(boost::shared_ptr<SceneNode> node);

		virtual ResourceFlags GetFlags() const;
		virtual void UpdateState(boost::shared_ptr<IDataFilter> stateData);

		virtual const uuid &GetId() const;
		virtual void SetId(const uuid &id);

		virtual const char *GetMimeType() const;
		virtual const char *GetFileExtension() const;

		virtual bool IsFileSerializable() const;
		virtual bool IsMemorySerializable() const;

		virtual boost::shared_ptr<IDataFilter> GetSerializedData() const;

		virtual LightType GetType() const;
		virtual void SetType(LightType type);

		virtual Color GetDiffuseColor() const;
		virtual void SetDiffuseColor(const Color &c);

		virtual Color GetSpecularColor() const;
		virtual void SetSpecularColor(const Color &c);

		virtual Vector3 GetDirection() const;
		virtual void SetDirection(const Vector3 &direction) const;

		virtual void GetAttenuation(float &range, float &constant, float &linear, float &quadratic) const;
		virtual void SetAttenuation(float range, float constant, float linear, float quadratic);

		virtual void GetSpotRange(float &innerAngle, float &outerAngle, float &falloff);
		virtual void SetSpotRange(float innerAngle, float outerAngle, float falloff);

		virtual void SetTransform(const ReversibleTransform &trans);
		virtual const ReversibleTransform &GetTransform() const;

		virtual bool IsShadowCasting() const;
		virtual void SetShadowCasting(bool value);

		static boost::shared_ptr<Light>
		LoadLight(boost::shared_ptr<OgreRenderer> renderer, const JsonObject &data);
	private:
		uuid id;
		Ogre::SceneManager *scene;
		Ogre::Light *light;
		ReversibleTransform transform;
	};

}; // namespace XernOgre

#endif //XERN_LAMP_HPP
